import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: '/login',
        component: () => import('@/views/login.vue')
    },
    {
        path: '/register',
        component: () => import("@/views/register.vue")
    },
    {
        path: '/personal',
        component: () => import('@/views/personal.vue')
    },
    {
        path: '/edit_profile',
        component: () => import('@/views/edit_profile.vue')
    },
    {
        path: '/index',
        component: () => import('@/views/index.vue')
    },
    {
        path: '/articleDetail',
        component: () => import('@/views/articleDetail.vue')
    },
    {
        path: '/commentList',
        component: () => import('@/views/commentList.vue')
    },
    {
        path: '/event-focus',
        component: () => import('@/views/event-focus.vue')
    },
    {
        path: '/collections',
        component: () => import('@/views/collections.vue')
    },
    {
        path: '/comments-head',
        component: () => import('@/views/comments-head.vue')
    },
    {
        path: '/searchPage',
        component: () => import('@/views/searchPage.vue')
    },
    {
        path: '/Labelmanagement',
        component: () => import('@/views/Labelmanagement.vue')
    }
]

const router = new VueRouter({
    routes,
    mode: 'history'
})

router.beforeEach((to, from, next) => {
    let token = localStorage.getItem('Token')
    if (to.path === '/personal' && !token) {
        next('/login')
    } else {
        next()
    }
})

export default router